﻿using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using YJKRGeometry;
using SectionSignAndFilled.StairsRoomPlanSign.ControlLayer;

namespace SectionSignAndFilled.StairsRoomPlanSign.ModelLayer
{
	public class ColumnPacker
	{
		public List<Curve> LstBoundCurves
		{
			get
			{
				return this.m_lstBoundCurves;
			}
			private set
			{
				this.m_lstBoundCurves = value;
			}
		}

		public ColumnPacker(FamilyInstance inputFamilyInstance, StairPlanDataPacker useData, RevitLinkInstance inputRevitLinkInstacne = null)
		{
			this.m_useLinkInstance = inputRevitLinkInstacne;
			BoundingBoxXYZ boundingBoxXYZ = inputFamilyInstance.get_BoundingBox(null);
			this.m_thisColumn = inputFamilyInstance;
			this.m_nThisElementId = this.m_thisColumn.Id.IntegerValue;
			XYZ xyz = boundingBoxXYZ.Min;
			XYZ xyz2 = boundingBoxXYZ.Max;
			this.m_useTransform = null;
			if (this.m_useLinkInstance != null)
			{
				this.m_nThisRevitLinkInstanceId = this.m_useLinkInstance.Id.IntegerValue;
				this.m_useTransform = this.m_useLinkInstance.GetTransform();
				xyz = Geometry.TransformPoint(xyz, this.m_useTransform);
				xyz2 = Geometry.TransformPoint(xyz2, this.m_useTransform);
			}
			this.m_columnBoundingBoxPacker = new BoundingBoxPakcer(xyz, xyz2, useData.NowViewZ, new List<XYZ>
			{
				useData.UseView.RightDirection,
				useData.UseView.UpDirection
			});
			this.LstBoundCurves = ColumnCurveGeter.GetCurveGeter(SignManger.CommandData).GetColumnCurves(inputFamilyInstance, useData.NowViewZ, this.m_useTransform);
		}

		public bool IfTwoWallIntersectionInThis(XYZ point, WallElementPacker inputWallOne, WallElementPacker inputWallTwo)
		{
			XYZ pt = new XYZ(point.X, point.Y, SignManger.ThisStairPlandDataPacker.NowViewZ);
			int num = Geometry.PointInPloygon(this.m_columnBoundingBoxPacker.LstBoundLine.Cast<Curve>().ToList<Curve>(), pt);
			return num == 1 && this.IfWallNearThis(inputWallOne) && this.IfWallNearThis(inputWallTwo);
		}

		private void IsPiontIn(WallElementPacker inputWallOne, out int nResultOneStart, out int nResultOneEnd)
		{
			XYZ xyz = inputWallOne.UseMidCurve.GetEndPoint(0);
			XYZ xyz2 = inputWallOne.UseMidCurve.GetEndPoint(1);
			xyz = new XYZ(xyz.X, xyz.Y, SignManger.ThisStairPlandDataPacker.NowViewZ);
			xyz2 = new XYZ(xyz2.X, xyz2.Y, SignManger.ThisStairPlandDataPacker.NowViewZ);
			nResultOneStart = Geometry.PointInPloygon(this.m_columnBoundingBoxPacker.LstBoundLine.Cast<Curve>().ToList<Curve>(), xyz);
			nResultOneEnd = Geometry.PointInPloygon(this.m_columnBoundingBoxPacker.LstBoundLine.Cast<Curve>().ToList<Curve>(), xyz2);
		}

		private bool IfWallNearThis(WallElementPacker inputWallOne)
		{
			foreach (Curve curve in this.LstBoundCurves)
			{
				foreach (Curve curve2 in inputWallOne.LstCurveIntersectionUse)
				{
                    if (8 == (int)curve.Intersect(curve2))
					{
						return true;
					}
				}
			}
			return false;
		}

		private BoundingBoxPakcer m_columnBoundingBoxPacker;

		private FamilyInstance m_thisColumn;

		private int m_nThisElementId = -1;

		private RevitLinkInstance m_useLinkInstance;

		private Transform m_useTransform;

		private int m_nThisRevitLinkInstanceId = -1;

		private List<Curve> m_lstBoundCurves = new List<Curve>();
	}
}
